#!/usr/bin/env python  
# encoding: utf-8   

""" 
@version: v1.0 
@author: null 
@software: PyCharm 
@file: utils.py 
@time: 2017.5.4 19:00 
"""
#工具类
import requests

def cookieStr2cookieObj(cookiestr):
    ckarray = cookiestr.split(";")
    cookie = {}
    for i in range(0, len(ckarray) - 1):
        v = ckarray[i].split("=")
        cookie[v[0].strip()] = v[1].strip()
    ck = requests.utils.cookiejar_from_dict(cookie, cookiejar=None, overwrite=True)
    return ck
    pass

def cookieObj2cookieStr(cookieobj):
    cookie = ''
    for k, v in requests.utils.dict_from_cookiejar(cookieobj).items():
        cookie = cookie + k + "=" + v + "; "
    return cookie
    pass

def cookieStr2cookieDic(cookiestr):
    ckarray = cookiestr.split(";")
    cookie = {}
    for i in range(0, len(ckarray) - 1):
        v = ckarray[i].split("=")
        cookie[v[0].strip()] = v[1].strip()
    return cookie
    pass
